import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class day_06_IO_Test_04 {
    public static void main(String[] args) throws IOException {
        // 对文件中的数据进行排序 —— 改写
        FileInputStream fileInputStream = new FileInputStream("sort.txt");
        StringBuilder stringBuilder = new StringBuilder();

        int b;
        while ((b = fileInputStream.read()) != -1) {
            stringBuilder.append((char) b);
        }

        fileInputStream.close();

        // 对文件中的数据进行排序
        Integer[] arr = Arrays.stream(stringBuilder.toString().split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);

        // 转换为需要写出的格式
        String s = Arrays.toString(arr).replace(",", "-");
        String result = s.substring(1, s.length() - 1);

        // 写出文件
        FileWriter fileWriter = new FileWriter("sort.txt");
        fileWriter.write(result);
        fileWriter.close();
    }
}
